Trivy 0.56.0 から misconfiguration のスキャン時に非推奨のルールのチェックはデフォルト無効になりました

Trivy 0.56.0 から misconfiguration のスキャン時に非推奨のルールのチェックはデフォルト無効になりました

Clock Icon2024.10.07

Trivy を用いて CloudFormation テンプレートのスキャンを行っているプロジェクトで、.trivyignore に設定していたルールを見直していたところ、ignore から外してもスキャン結果が同じになり、外したルールが検知されない事象が発生しました。

原因を調べてみると Trivy 0.56.0 で非推奨のルールのチェックはデフォルト無効に変更されていました。

misconf: Disable deprecated checks by default (#7632) (82e2adc)
https://github.com/aquasecurity/trivy/blob/main/CHANGELOG.md#0560-2024-10-03

今後、非推奨のルールのチェックを行いたい場合は --include-deprecated-checks オプションを付与する必要があります。

Trivy 0.55.2 と 0.56.0 のスキャン結果を比較する

検証のため 0.56.0 の前のバージョンである 0.55.2 とスキャン結果を比較してみます。
また、0.56.0 に --include-deprecated-checks オプションを付与したスキャン結果も検証しました。

スキャン対象 CloudFormation テンプレート

以下の CloudFormation テンプレートに対しスキャンを行います。
S3 に対してのすべての操作を許可する IAM ロールを作成する CloudFormation テンプレートになります。

AWSTemplateFormatVersion: "2010-09-09"

Resources:
  IAMRole:
    Type: AWS::IAM::Role
    Properties:
      RoleName: "ROLE-NAME"
      Policies:
        - PolicyName: "AllowS3"
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Action: "s3:*"
                Resource: "*"

Trivy 0.55.2 のスキャン結果

Trivy でスキャンは docker run コマンドを用いてバージョンを切り替えました。

docker run --rm -v $PWD:/cfn aquasec/trivy:0.55.2 conf /cfn

結果は以下の通り、AVD-AWS-0057 の * について指摘されました。


cfn.yml (cloudformation)
========================
Tests: 7 (SUCCESSES: 5, FAILURES: 2, EXCEPTIONS: 0)
Failures: 2 (UNKNOWN: 0, LOW: 0, MEDIUM: 0, HIGH: 2, CRITICAL: 0)

HIGH: IAM policy document uses sensitive action 's3:*' on wildcarded resource '*'
════════════════════════════════════════
You should use the principle of least privilege when defining your IAM policies. This means you should specify each exact permission required without using wildcards, as this could cause the granting of access to certain undesired actions, resources and principals.

See https://avd.aquasec.com/misconfig/avd-aws-0057
────────────────────────────────────────
 cfn.yml:12
   via cfn.yml:12 ()
    via cfn.yml:11-15 ()
     via cfn.yml:4-15 (IAMRole)
────────────────────────────────────────
   4     IAMRole:
   .   
  12 [             Statement:
  ..   
  15                   Resource: "*"
────────────────────────────────────────

HIGH: IAM policy document uses wildcarded action 's3:*'
════════════════════════════════════════
You should use the principle of least privilege when defining your IAM policies. This means you should specify each exact permission required without using wildcards, as this could cause the granting of access to certain undesired actions, resources and principals.

See https://avd.aquasec.com/misconfig/avd-aws-0057
────────────────────────────────────────
 cfn.yml:12
   via cfn.yml:12 ()
    via cfn.yml:11-15 ()
     via cfn.yml:4-15 (IAMRole)
────────────────────────────────────────
   4     IAMRole:
   .   
  12 [             Statement:
  ..   
  15                   Resource: "*"
────────────────────────────────────────

Trivy 0.56.0 のスキャン結果

先ほどのコマンドからバージョンを変更したコマンドを使用します。

docker run --rm -v $PWD:/cfn aquasec/trivy:0.56.0 conf /cfn

AVD-AWS-0057 は非推奨のルールのため、チェックされず、何も出力されませんでした。

Trivy 0.56.0 に --include-deprecated-checks オプションを付与したスキャン結果

--include-deprecated-checks オプションを付与し、0.55.2 と同一の結果になるか検証します。

docker run --rm -v $PWD:/cfn aquasec/trivy:0.56.0 conf /cfn --include-deprecated-checks

スキャン結果は以下となり、再度 AVD-AWS-0057 について指摘されました。


cfn.yml (cloudformation)
========================
Tests: 24 (SUCCESSES: 22, FAILURES: 2, EXCEPTIONS: 0)
Failures: 2 (UNKNOWN: 0, LOW: 0, MEDIUM: 0, HIGH: 2, CRITICAL: 0)

HIGH: IAM policy document uses sensitive action 's3:*' on wildcarded resource '*'
════════════════════════════════════════
You should use the principle of least privilege when defining your IAM policies. This means you should specify each exact permission required without using wildcards, as this could cause the granting of access to certain undesired actions, resources and principals.

See https://avd.aquasec.com/misconfig/avd-aws-0057
────────────────────────────────────────
 cfn.yml:12
   via cfn.yml:12 ()
    via cfn.yml:11-15 ()
     via cfn.yml:4-15 (IAMRole)
────────────────────────────────────────
   4     IAMRole:
   .   
  12 [             Statement:
  ..   
  15                   Resource: "*"
────────────────────────────────────────

HIGH: IAM policy document uses wildcarded action 's3:*'
════════════════════════════════════════
You should use the principle of least privilege when defining your IAM policies. This means you should specify each exact permission required without using wildcards, as this could cause the granting of access to certain undesired actions, resources and principals.

See https://avd.aquasec.com/misconfig/avd-aws-0057
────────────────────────────────────────
 cfn.yml:12
   via cfn.yml:12 ()
    via cfn.yml:11-15 ()
     via cfn.yml:4-15 (IAMRole)
────────────────────────────────────────
   4     IAMRole:
   .   
  12 [             Statement:
  ..   
  15                   Resource: "*"
────────────────────────────────────────

まとめ

  • Trivy 0.56.0 では、非推奨のルールのチェックがデフォルトで無効になりました
  • これにより、以前は検知されていた問題が見つからなくなる可能性があります
  • Trivy 0.56.0 以降で非推奨のルールのチェックを行うには --include-deprecated-checks オプションを付与しましょう

この記事をシェアする

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.